﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.SessionState;
using AiXiu.Common;

namespace AiXiu.WebSite.Handler
{
    /// <summary>
    /// CaptchaHandler 的摘要说明
    /// </summary>
    public class CaptchaHandler : IHttpHandler, IRequiresSessionState
    {

        public void ProcessRequest(HttpContext context)
        {
            //将画好的图片输出到流中，并且设置图片的格式
            var cap = new CaptchaGenerator();
            context.Session["yzm"] = cap.Text;
            var t = context.Session["yzm"];
            var bit = cap.Image;
            bit.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
            //释放图片资源
            bit.Dispose();
            //结束响应
            context.Response.End();
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}